defmodule Giom.Accounting.Point do
  use Ecto.Schema
  import Ecto.Changeset

  @primary_key {:point_code, :string, autogenerate: false}
  @derive {Phoenix.Param, key: :point_code}
  schema "points" do
    field :branch_code, :string
    field :mgmt_code, :string
    field :point_name, :string
    field :type, :string
	
	field :group_code,  :string
	field :group_code2, :string
	field :group_code3, :string
	
	field :expiry_date, :utc_datetime
	field :create_date, :utc_datetime
	field :edit_date, :utc_datetime
	
	field :creator, :string
	field :editor, :string
	
    timestamps()
  end

  @doc false
  def changeset(point, attrs) do
    point
    |> cast(attrs, [:point_code, :point_name, :branch_code, :mgmt_code, :type])
    |> validate_required([:point_code, :point_name, :branch_code, :mgmt_code, :type])
    |> unique_constraint(:point_code, name: :points_pkey)
  end
end
